package br.com.winesys.geta.databinding.componentBinder;

import javax.swing.text.JTextComponent;
import br.com.winesys.geta.databinding.ComponentBinder;

public final class JTextComponentBinder implements ComponentBinder<JTextComponent> {

	private static final ComponentBinder<JTextComponent> INSTANCE = new JTextComponentBinder();

	public static ComponentBinder<JTextComponent> getInstance() {
		return INSTANCE;
	}

	private JTextComponentBinder() {
	}

	@Override
	public Object read(JTextComponent component) {
		return component.getText();
	}

	@Override
	public void write(JTextComponent component, Object value) {
		if (value == null) {
			component.setText("");
		} else {
			component.setText(value.toString());
		}
		component.setCaretPosition(0);
	}
}
